$(document).ready(init);

var atNum = 0;
var attentionNum = 0;
var commentNum = 0;
var feedNum = 0;
var messageNum = 0;

function init() {
	setInterval(checkNewMessage, 15000);
}

function checkNewMessage() {
	var requestUrl = 'http://t.qiyi.com/api/common/new_msg.php';

	$.get(requestUrl, '', newMessageCallback, 'json');
}

function newMessageCallback(data) {
	var hasBadge = false;
	if (data.code != 'A00000') {
		return ;
	}

	if (data.data.atme != 0 || data.data.attention != 0 || data.data.comment != 0 || data.data.feed != 0 || data.data.msg != 0) {
		hasBadge = true;
	}

		atmeNum = data.data.atme;



		commentNum = data.data.comment;



		feedNum = data.data.feed;


		messageNum = data.data.msg;


	if (hasBadge) {
		chrome.browserAction.setBadgeText({text: '!'});
	} else {
		chrome.browserAction.setBadgeText({text: ''});
	}
}